<?php
/**
 *
 * @Author: phpzhi <phpzhi@qq.com><https://www.phpzhi.com>
 * @Date: 2019/11/11 9:36
 */

namespace app\api\controller;


use app\api\model\goods\GoodsCart;
use app\common\controller\Api;

class Cart extends Api
{
    protected $noNeedRight = ['*'];
    /**
     * 添加购物车订单
     */
    public function create()
    {
        $data = $this->request->post();
        list($goodsId, $goodsNum, $goodsSkuId, $isNew) = [
            $data['goodsId'] ?? 0,
            $data['goodsNum'] ?? 1,
            $data['goodsSkuId'] ?? '',
            $data['isBuy'] ?? 1
        ];
        if (!$goodsId || !is_numeric($goodsId)) $this->error('参数错误');

        $res = GoodsCart::createCart($this->auth->id, $goodsId, $goodsNum, $goodsSkuId, $isNew);
        if (!$res) $this->error(GoodsCart::getErrorInfo());
        else $this->success('request:ok', ['cartId' => $res->id]);
    }

    /**
     * 更新购物车
     * @param int $id 购物车id
     */
    public function update($id)
    {
        //
    }

    /**
     * 删除购物车
     * @param int $id 购物车id
     */
    public function delete($id)
    {
        //
    }
}
